﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Com.Framework;
using Com.Framework.Data;

namespace Com.Library.DB.UserCard
{
	public enum CodeCardStatus : byte
	{
		None = 0,
		Create = 1,
		Lost = 2,
		Remove = 3
	}

	public class UserCardModel
	{
		public static void Create(int UserNo, string CardNo)
		{
			UserCardCreateArguments arg = new UserCardCreateArguments();
			arg.n4UserNo = UserNo;
			arg.strCardNo = CardNo;

			UserCardCreate sp = new UserCardCreate();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static void Modify(int UserCardNo, int? UserNo, string CardNo, string ModifyManagerName)
		{
			UserCardModifyArguments arg = new UserCardModifyArguments();
			arg.n4UserCardNo = UserCardNo;
			if (UserNo.HasValue)
				arg.n4UserNo = UserNo.Value;
			if (CardNo != string.Empty && CardNo != null)
				arg.strCardNo = CardNo;
			if (ModifyManagerName != string.Empty && ModifyManagerName != null)
				arg.strModifyManagerName = ModifyManagerName;

			UserCardModify sp = new UserCardModify();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static UserCardEntity GetInfo(string CardNo)
		{
			UserCardGetInfoArguments arg = new UserCardGetInfoArguments();
			arg.strCardNo = CardNo;

			UserCardGetInfo sp = new UserCardGetInfo();
			sp.SetArguments(arg);
			UserCardEntity info = sp.ExecuteNonQuery();

			return info;
		}

		public static UserCardEntity GetInfo(int UserCardNo)
		{
			UserCardGetInfoArguments arg = new UserCardGetInfoArguments();
			arg.n4UserCardNo = UserCardNo;

			UserCardGetInfo sp = new UserCardGetInfo();
			sp.SetArguments(arg);
			UserCardEntity info = sp.ExecuteNonQuery();

			return info;
		}

		public static ListData<UserCardEntity, OutputEntity> GetList(int UserNo, CodeCardStatus CodeStatus, int PageNo, byte PageSize)
		{
			UserCardGetListArguments arg = new UserCardGetListArguments();
			arg.n4UserNo = UserNo;
			arg.CodeStatus = CodeStatus.Parse((byte)0);
			arg.PageNo = PageNo;
			arg.PageSize = PageSize;
			UserCardGetList sp = new UserCardGetList();
			sp.SetArguments(arg);
			List<UserCardEntity> list = sp.Execute();
			OutputEntity info = sp.GetOutput();

			return new ListData<UserCardEntity, OutputEntity>(list, info);
		}

		public static ListData<UserCardManagerEntity, OutputEntity> GetListManager(CodeCardStatus CodeStatus, int? UserNo, string CardNo, int PageNo, byte PageSize)
		{
			UserCardGetListManagerArguments arg = new UserCardGetListManagerArguments();
			if (CardNo != string.Empty && CardNo != null)
				arg.strCardNo = CardNo;
			if (UserNo.HasValue)
				arg.n4UserNo = UserNo.Value;
			arg.CodeStatus = CodeStatus.Parse((byte)0);
			arg.PageNo = PageNo;
			arg.PageSize = PageSize;

			UserCardGetListManager sp = new UserCardGetListManager();
			sp.SetArguments(arg);
			List<UserCardManagerEntity> list = sp.Execute();
			OutputEntity info = sp.GetOutput();

			return new ListData<UserCardManagerEntity, OutputEntity>(list, info);
		}

		public static void Remove(int UserCardNo, string ManagerName, string Desc)
		{
			UserCardRemoveArguments arg = new UserCardRemoveArguments();
			arg.n4UserCardNo = UserCardNo;
			arg.strModifyManagerName = ManagerName;
			arg.strDesc = Desc;

			UserCardRemove sp = new UserCardRemove();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}

		public static void Restore(int UserCardNo, string ManagerName, string Desc)
		{
			UserCardRestoreArguments arg = new UserCardRestoreArguments();
			arg.n4UserCardNo = UserCardNo;
			arg.strModifyManagerName = ManagerName;
			arg.strDesc = Desc;

			UserCardRestore sp = new UserCardRestore();
			sp.SetArguments(arg);
			sp.ExecuteNonQuery();
		}
	}
}
